public class test {
    // 蛋糕的美味值(⭐⭐)
    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int k = in.nextInt();
            int[] arr = new int[20];
            for(int i = 0;i < n;i++) {
                arr[i] = in.nextInt();
            }
            //代表有(1<<n-1)种排列方式
            //转换成二进制,如:10101,代表选1,3,5块蛋糕
            long sum = 0;
            long max = 0;
            for(int i = 0;i < (1<<n) ; i++) {
                //System.out.println(i);
                int index = 0;
                for(int num = i;num > 0;num = num >> 1) {
                    //代表此时选这个蛋糕
                    if(num % 2 == 1) {
                        //System.out.println(sum);
                        sum += arr[index];
                    }
                    index++;
                }
                if(sum < k) {
                    max = Math.max(max, sum);
                }
                sum = 0;
            }
            System.out.println(max);
        }
    }
    // 走迷宫(⭐⭐)

    public class Main1 {
        public static int row;
        public static int col;
        public static int[] start;
        public static int[] end;
        public static int[][] nums;
        public static boolean[][] count;
        public static int[] dx = {0,0,1,-1};
        public static int[] dy = {1,-1,0,0};
        public static int min = Integer.MAX_VALUE;
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            row = in.nextInt();
            col = in.nextInt();
            end = new int[2];
            start = new int[2];
            nums = new int[row][col];
            count = new boolean[row][col];
            for(int i = 0;i < row;i++) {
                for(int j = 0;j < col;j++) {
                    nums[i][j] = in.nextInt();
                }
            }
            start[0] = in.nextInt();
            start[1] = in.nextInt();
            end[0] = in.nextInt();
            end[1] = in.nextInt();
            dfs(start[0]-1,start[1]-1,0);
            System.out.println(min < Integer.MAX_VALUE ? min : -1);
        }
        public static void dfs(int a,int b,int len) {
            Queue<int[]> queue = new LinkedList<>();
            queue.add(new int[] {a,b});
            while(!queue.isEmpty()) {
                int size = queue.size();
                for(int j = 0;j < size;j++) {
                    int[] t = queue.poll();
                    for(int i = 0;i < 4;i++) {
                        int x = t[0] + dx[i];
                        int y = t[1] + dy[i];
                        if(x >= 0 && x < row && y >= 0 && y < col && !count[x][y] && nums[x][y] == 1) {
                            count[x][y] = true;
                            queue.add(new int[] {x,y});
                            if(x == end[0] - 1 && y == end[1] - 1) {
                                min = len + 1;
                            }
                        }
                    }
                }
                len++;
            }
            return ;
        }
    }
    //最少操作数(⭐⭐)
    public class Main {
        public static int n;
        public static int k;
        public static int len;
        public static HashSet<Integer> count;
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            n = in.nextInt();
            k = in.nextInt();
            count = new HashSet<Integer>();
            dfs();
            System.out.println(len);
        }
        public static void dfs() {
            Queue<Integer> queue = new LinkedList<Integer>();
            int llen = 0;
            queue.add(n);
            while(!queue.isEmpty()) {
                int size = queue.size();
                for(int j = 0;j < size;j++) {
                    int num = queue.poll();
                    if(num > k){
                        if(num - 1 == k){
                            len = llen + 1;
                            return;
                        }
                        if(!count.contains(num - 1)){
                            count.add(num - 1);
                            queue.add(num - 1);
                        }
                        continue;
                    }
                    for(int i = 0;i < 3;i++) {
                        if(i == 0 && !count.contains(num + 1)) {
                            if(num + 1 == k) {
                                len = llen + 1;
                                return;
                            }
                            count.add(num + 1);
                            queue.add(num + 1);
                        }else if(i == 1 && !count.contains(num - 1)) {
                            if(num - 1 == k) {
                                len = llen + 1;
                                return;
                            }
                            count.add(num - 1);
                            queue.add(num - 1);
                        }else if(i == 2 && !count.contains(num * 2)) {
                            if(num * 2 == k) {
                                len = llen + 1;
                                return;
                            }
                            count.add(num * 2);
                            queue.add(num * 2);
                        }
                    }
                }
                llen++;
            }
        }
    }
}
